Fix flaky Mocha Postgres tests with shared Npgsql helper#9981
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses intermittent CI failures in Mocha.EntityFrameworkCore.Postgres.Tests caused by EF Core’s ManyServiceProvidersCreatedWarning being triggered (and treated as an error) when many test-created service providers accumulate during a run. It centralizes the Npgsql + warning configuration into a single helper and routes all DbContext option construction through it to eliminate ordering/parallelism-dependent flakes.
Changes:
- Added
UseTestNpgsqlextension methods to consistently configure the Npgsql provider and ignoreCoreEventId.ManyServiceProvidersCreatedWarning. - Updated all Postgres test call sites to use
UseTestNpgsqlinstead of inlineUseNpgsql(...)/ConfigureWarnings(...). - Removed now-unneeded EF diagnostics
usingdirectives and duplicated inline warning suppression.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/Mocha/test/Mocha.EntityFrameworkCore.Postgres.Tests/SchedulingServiceRegistrationTests.cs | Switches test DbContext registration to the shared UseTestNpgsql helper. |
| src/Mocha/test/Mocha.EntityFrameworkCore.Postgres.Tests/SagaStateEntityConfigurationTests.cs | Uses UseTestNpgsql for model-building context options. |
| src/Mocha/test/Mocha.EntityFrameworkCore.Postgres.Tests/SagaServiceRegistrationTests.cs | Routes both direct options creation and DI registration through UseTestNpgsql. |
| src/Mocha/test/Mocha.EntityFrameworkCore.Postgres.Tests/PostgresSchedulingIntegrationTests.cs | Replaces duplicated inline warning suppression with UseTestNpgsql. |
| src/Mocha/test/Mocha.EntityFrameworkCore.Postgres.Tests/PostgresSagaStoreTests.cs | Uses UseTestNpgsql for DbContext creation in saga store setup. |
| src/Mocha/test/Mocha.EntityFrameworkCore.Postgres.Tests/PostgresOutboxIntegrationTests.cs | Consolidates DbContext configuration via UseTestNpgsql. |
| src/Mocha/test/Mocha.EntityFrameworkCore.Postgres.Tests/PostgresMessageOutboxTests.cs | Updates all DbContextOptionsBuilder usage to UseTestNpgsql. |
| src/Mocha/test/Mocha.EntityFrameworkCore.Postgres.Tests/PostgresMessageInboxTests.cs | Updates DbContext options creation to use UseTestNpgsql. |
| src/Mocha/test/Mocha.EntityFrameworkCore.Postgres.Tests/OutboxServiceRegistrationTests.cs | Uses UseTestNpgsql and removes inline warning suppression. |
| src/Mocha/test/Mocha.EntityFrameworkCore.Postgres.Tests/OutboxEntityConfigurationTests.cs | Uses UseTestNpgsql for design-time model creation. |
| src/Mocha/test/Mocha.EntityFrameworkCore.Postgres.Tests/InboxServiceRegistrationTests.cs | Switches DbContext registration to UseTestNpgsql. |
| src/Mocha/test/Mocha.EntityFrameworkCore.Postgres.Tests/Helpers/TestDbContextOptionsBuilderExtensions.cs | Introduces the shared UseTestNpgsql helper (generic + non-generic overloads) and central warning suppression. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ManyServiceProvidersCreatedWarningwhen a context is created past that threshold. Because it depends on test ordering and parallelism, the failure surfaced intermittently in CI (the*ServiceRegistrationtests).UseTestNpgsqloptions-builder helper that applies the Npgsql provider and ignores that warning, and route every context-building call site through it. This replaces the inline ignores that previously covered only some call sites.Test plan
--parallel none, which forces the sequential ordering that exposes the flake: the affected tests fail before the change and pass after.